package com.qqt.csr.route.service;

import com.qqt.csr.common.enums.YesOrNotEnum;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qqt.csr.route.entity.RouteBizRule;
import com.qqt.csr.route.mapper.RouteBizRuleMapper;
@Service
public class RouteBizRuleService extends ServiceImpl<RouteBizRuleMapper, RouteBizRule> {

    
    public int updateBatch(List<RouteBizRule> list) {
        return baseMapper.updateBatch(list);
    }
    
    public int updateBatchSelective(List<RouteBizRule> list) {
        return baseMapper.updateBatchSelective(list);
    }
    
    public void batchInsert(List<RouteBizRule> list) {
        if(CollectionUtils.isEmpty(list)){
            return;
        }
        Date currentTime = new Date();
        list.forEach(item->{
            item.setCreateTime(currentTime);
            item.setUpdateTime(currentTime);
            item.setDeleteFlag(YesOrNotEnum.NOT.getValue());
        });
        baseMapper.batchInsert(list);
    }

    public List<RouteBizRule> queryByRuleId(Integer ruleId){
        return this.lambdaQuery().select().eq(RouteBizRule::getRuleId, ruleId).list();
    }

    /**
     * 删除业务规则
     * @param ruleId
     */
    public void deleteByRuleId(Integer ruleId){
        this.lambdaUpdate()
                .set(RouteBizRule::getDeleteFlag, YesOrNotEnum.YES.getValue())
                .set(RouteBizRule::getUpdateTime, new Date())
                .eq(RouteBizRule::getRuleId, ruleId).update();
    }
}
